﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using YArchitech.LIB;
using YJKCopyModel.Forms;

namespace YJKCopyModel.GeothermalPipeQuickModel
{
	internal class GeothermalRespondHanlder : IResponseHanlder
	{
		public void AddEndTime(DateTime inputDataTime)
		{
			this.endTime = inputDataTime;
		}

		public void AddOneResponse(RevitModelRebuildResponse inputResponse)
		{
			this.lstResponse.Add(inputResponse);
		}

		public void AddStartTime(DateTime inputDataTime)
		{
			this.startTime = inputDataTime;
		}

		public void HanlderResponse()
		{
			StringBuilder stringBuilder = new StringBuilder();
			int num = (from n in this.lstResponse
			where n.IfSucess
			select n).Count<RevitModelRebuildResponse>();
			stringBuilder.AppendLine(string.Format("成功生成地热盘管{0}组", num));
			TimeSpan timeSpan = this.endTime.Subtract(this.startTime).Duration();
			string arg = string.Empty;
			bool flag = timeSpan.Hours > 0;
			if (flag)
			{
				arg = string.Concat(new string[]
				{
					timeSpan.Hours.ToString(),
					"小时",
					timeSpan.Minutes.ToString(),
					"分",
					timeSpan.Seconds.ToString(),
					"秒"
				});
			}
			else
			{
				arg = timeSpan.Minutes.ToString() + "分" + timeSpan.Seconds.ToString() + "秒";
			}
			stringBuilder.AppendLine(string.Format("共耗时{0}", arg));
			Process currentProcess = Process.GetCurrentProcess();
			IntPtr mainWindowHandle = currentProcess.MainWindowHandle;
			YJKWindowHandle owner = new YJKWindowHandle(mainWindowHandle);
			TransResultForm transResultForm = new TransResultForm(stringBuilder.ToString());
			transResultForm.ShowDialog(owner);
			this.lstResponse = new List<RevitModelRebuildResponse>();
		}

		private DateTime startTime;

		private DateTime endTime;

		private List<RevitModelRebuildResponse> lstResponse = new List<RevitModelRebuildResponse>();
	}
}
